package com.tepth.maintenancesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.tepth.maintenancesystem.R;
import com.tepth.maintenancesystem.bean.MaintainListWork;
import com.tepth.maintenancesystem.untils.Untils;

import java.util.List;

/**
 * Created by LHQ on 2016/12/19.
 */

public class GuojianAdapter extends BaseAdapter {

    private List<MaintainListWork> mDatas;
    private Context mContext;
    private LayoutInflater layoutInflater;

    public GuojianAdapter(Context context,List<MaintainListWork> mDatas){
        this.mContext = context;
        this.mDatas = mDatas;
        layoutInflater = LayoutInflater.from(this.mContext);
    }
    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.maintain_details_guojian_item, parent, false);
            viewHolder.tv_guojian_details = (TextView) convertView.findViewById(R.id.tv_guojian_details);
            viewHolder.tv_guojian_name= (TextView) convertView.findViewById(R.id.tv_guojian_name);
            viewHolder.guojian_checkbox= (ImageView) convertView.findViewById(R.id.guojian_checkbox);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        MaintainListWork obj=mDatas.get(position);
        viewHolder.tv_guojian_details.setText(obj.getContentTypeName());
        if(obj.getConfirmPersonName().equals("null")||obj.getConfirmPersonName().equals("")){
            viewHolder.tv_guojian_name.setVisibility(View.GONE);
            if(obj.isGuojian()){
                viewHolder.guojian_checkbox.setImageDrawable(Untils.getDrawable(mContext,R.drawable.details_right_red));
            }else{
                viewHolder.guojian_checkbox.setImageDrawable(Untils.getDrawable(mContext,R.drawable.details_right_grey));
            }
        }else{
            if(viewHolder.tv_guojian_details.getCurrentTextColor()==Untils.getColor(mContext,R.color.colorPrimary)){
                viewHolder.tv_guojian_name.setVisibility(View.GONE);
                viewHolder.guojian_checkbox.setImageDrawable(Untils.getDrawable(mContext,R.drawable.details_right_grey));
            }else{
                viewHolder.tv_guojian_name.setVisibility(View.VISIBLE);
                viewHolder.tv_guojian_name.setText(obj.getConfirmPersonName());
                viewHolder.guojian_checkbox.setImageDrawable(Untils.getDrawable(mContext,R.drawable.details_right_green));
            }
        }
        return convertView;
    }

    private static class ViewHolder {
        TextView tv_guojian_details,tv_guojian_name;
        ImageView guojian_checkbox;
    }
}
